//
//  NoticeTableViewCell.m
//  CMVRFForIOS
//
//  Created by zhangnorman on 15/4/4.
//  Copyright (c) 2015年 hvacapp. All rights reserved.
//

#import "NoticeTableViewCell.h"




@interface NoticeTableViewCell()

@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *detail;
@property (nonatomic, strong) UILabel *from;
@property (nonatomic, strong) UIImageView *noticeIcon;
@property (nonatomic, strong) UILabel *date;

@end

@implementation NoticeTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    
    return self;
}

/**
 *  初始化视图view
 */
- (void)setupViews {
    self.contentView.width = kScreen_Width - CELL_PADDING_RIGTH_AND_IMAGE;
    
    //是否是新公共图标
    self.noticeIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"new_notice_icon"]];
    self.noticeIcon.x = CELL_PADDING_LEFT;
    self.noticeIcon.y = CELL_PADDING_TOP;
    [self.contentView addSubview:self.noticeIcon];
    
    //标题
    self.title = [UILabel labelSingleLineFontSize:kListTitleFontSize content:@"标题"];
    self.title.x = CGRectGetMaxX(self.noticeIcon.frame) + 5;
    self.title.y = CELL_PADDING_TOP;
    self.title.width = self.contentView.width*2/3 - self.title.x;
    self.title.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.title];
    
    //详细
    self.detail = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"详细"];
    self.detail.x = self.title.x;
    self.detail.y = CGRectGetMaxY(self.title.frame) + CELL_CONTENT_MARGIN;
    self.detail.width = self.title.width;
    self.detail.textColor = CM_TABLE_DETAIL_COLOR;
    [self.contentView addSubview:self.detail];
    
    //确定cell的高度 以及设置右侧图标在中间
    self.contentView.height = CGRectGetMaxY(self.detail.frame) + CELL_PADDING_BOTTOM;
    
    //来源
    self.from = [UILabel labelSingleLineFontSize:10 content:@"来源"];
    self.from.y = self.contentView.height/2 + CELL_CONTENT_MARGIN/2;
    self.from.width = self.contentView.width/3 - CELL_CONTENT_MARGIN;
    self.from.x = self.contentView.width - self.from.width;
    self.from.textAlignment = NSTextAlignmentRight;
    self.from.textColor = CM_PLACEHOLDER_TEXT_COLOR;
    [self.contentView addSubview:self.from];
    
    //时间
    self.date = [UILabel labelSingleLineFontSize:10 content:@"2015-20-30"];
    self.date.x = self.contentView.width - self.date.width;
    self.date.y = self.contentView.height/2 - CELL_CONTENT_MARGIN/2 - self.date.height;
    self.date.textColor = CM_PLACEHOLDER_TEXT_COLOR;
    [self.contentView addSubview:self.date];
    
    //确定cell的高度 以及设置右侧图标在中间
    self.contentView.height = CGRectGetMaxY(self.from.frame) + CELL_PADDING_BOTTOM;
    self.noticeIcon.centerY = self.contentView.height/2;
    
}


/**
 *  设置数据
 *
 *  @param title  标题
 *  @param detail 详细
 *  @param from   来源
 */
- (void)setTitle:(NSString*)title andDetail:(NSString*)detail andFrom:(NSString*)from andDate:(NSString*)dateStr{
    CGSize size = [Tools sizeOfSingleLineText:from withSize:10];
    self.from.size = size;
    self.from.x = self.contentView.width - self.from.width;
    self.title.text = title;
    self.detail.text = detail;
    self.from.text = from;
    self.date.text = dateStr;
}

/**
 *  设置公共是否为新公告
 *
 *  @param isNew 标示
 */
- (void)setNewNoticeFlag: (BOOL)isNew {
    self.noticeIcon.hidden = !isNew;
}

/**
 *  获取cell的高度
 *
 *  @return 值
 */
- (float)getHeight {
    return self.contentView.height;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
